package com.ruoyi.web.controller.zzwt;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.zzw.LongListDto;
import com.ruoyi.common.core.domain.zzw.TIndicatorsInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ITIndicatorsInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 指标Controller
 *
 * @author xbx
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/system/indicators")
public class TIndicatorsInfoController extends BaseController {
    @Autowired
    private ITIndicatorsInfoService tIndicatorsInfoService;

    /**
     * 查询指标列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TIndicatorsInfo tIndicatorsInfo) {
        startPage();
        List<TIndicatorsInfo> list = tIndicatorsInfoService.selectTIndicatorsInfoList(tIndicatorsInfo);
        return getDataTable(list);
    }

    /**
     * 导出指标列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "指标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TIndicatorsInfo tIndicatorsInfo) {
        List<TIndicatorsInfo> list = tIndicatorsInfoService.selectTIndicatorsInfoList(tIndicatorsInfo);
        ExcelUtil<TIndicatorsInfo> util = new ExcelUtil<TIndicatorsInfo>(TIndicatorsInfo.class);
        util.exportExcel(response, list, "指标数据");
    }


    /**
     * 获取指标详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{cIndicatorsId}")
    public AjaxResult getInfo(@PathVariable("cIndicatorsId") Long cIndicatorsId) {
        return success(tIndicatorsInfoService.selectTIndicatorsInfoByCIndicatorsId(cIndicatorsId));
    }

    /**
     * 通过模块id获取指标详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/module/{cModuleId}")
    public AjaxResult getInfoByModuleId(@PathVariable("cModuleId") String cModuleId) {
        return success(tIndicatorsInfoService.listByCModuleId(cModuleId));
    }

    /**
     * 通过所属地区id获取指标详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/district/{cDistrictId}")
    public AjaxResult getInfoByDistrictId(@PathVariable("cDistrictId") String cDistrictId) {
        return success(tIndicatorsInfoService.listByCDistrictId(cDistrictId));
    }

    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/event/{cIndicatorsId}")
    public AjaxResult getRelatedEvent(@PathVariable("cIndicatorsId") String cIndicatorsId) {
        return success(tIndicatorsInfoService.getRelatedEvent(cIndicatorsId));
    }

    /**
     * 修改指标
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "指标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TIndicatorsInfo tIndicatorsInfo) {
        return toAjax(tIndicatorsInfoService.updateTIndicatorsInfo(tIndicatorsInfo));
    }


    /**
     * 新增指标
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @GetMapping(value = "/insert")
    @Log(title = "指标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TIndicatorsInfo tIndicatorsInfo) {
        return toAjax(tIndicatorsInfoService.insertTIndicatorsInfo(tIndicatorsInfo));
    }

    /**
     * 删除指标
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "指标", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult remove(@RequestBody LongListDto ids) {
        System.out.println(ids.toString());
        return toAjax(tIndicatorsInfoService.deleteTIndicatorsInfoByCIndicatorsIds(ids.getIds()));
    }
}
